#define  _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main()
{
	int n = 0, m = 0;
	while (scanf("%d %d", &n, &m) != EOF)
	{
		int arr[1000] = { 0 }, i = 0, sum = 0, count = 0, j = 0;
		for (i = 0; i < n; i++)
		{
			arr[i] = i + 1;
		}
		for (i = 0; 1; i++)
		{
			if (arr[i] == 0)
				i = 0;
			if (count == n - 1)
				break;
			sum++;
			if (sum == m)
			{
				count++;
				sum = 0;
				for (j = i; j < n; j++)
				{
					arr[j] = arr[j + 1];
				}
				i--;
			}
		}
		printf("%d\n", arr[i]);
	}
	return 0;
}